package cn.wch.blelib.host.core;


import androidx.annotation.NonNull;

/**
 * 连接规则
 */
public final class ConnRuler {
    private final String MAC;
    private final long connectTimeout;

    private final int readNullRetryCount;

    private final long readTimeout;
    private final long writeTimeout;

    private ConnRuler(Builder builder) {
        this.MAC = builder.MAC;
        this.connectTimeout = builder.connectTimeout;
        this.readNullRetryCount=builder.readNullRetryCount+1;
        this.readTimeout=builder.readTimeout;
        this.writeTimeout=builder.writeTimeout;
    }
    /**获取蓝牙mac地址*/
    public String getMAC() {
        return MAC;
    }
    /**获取连接超时时长（毫秒）*/
    public long getConnectTimeout() {
        return connectTimeout;
    }
    /**获取读超时时长（毫秒）*/
    public long getReadTimeout() {
        return readTimeout;
    }
    /**获取写超时时长（毫秒）*/
    public long getWriteTimeout() {
        return writeTimeout;
    }
    /**获取读空内容重试次数（没有读取到数据）*/
    public int getReadNullRetryCount() {
        return readNullRetryCount;
    }

    /**
     * 连接规则数据构造类
     */
    public static class Builder {
        /**蓝牙Mac地址*/
        private String MAC=null;
        /**连接超时时长*/
        private long connectTimeout=15000;
        /**读取{@code null}重试次数*/
        private int readNullRetryCount=10;
        /**读数据超时时长*/
        public long readTimeout=1000;
        /**写数据超时时长*/
        public long writeTimeout=1000;

        /**
         * 构造实体
         * @param MAC 蓝牙mac地址
         */
        public Builder(String MAC) {
            this.MAC = MAC;
        }

        /**
         * 连接超时
         * @param connectTimeout 连接超时时长（毫秒）
         * @return
         */
        public Builder connectTimeout(long connectTimeout) {
            this.connectTimeout = connectTimeout;
            return this;
        }

        /**
         * 读数据超时
         * @param readTimeout 读超时时长（毫秒）
         * @return
         */
        public Builder readTimeout(long readTimeout) {
            this.readTimeout = readTimeout;
            return this;
        }

        /**
         * 写超时时长
         * @param writeTimeout 写超时时长（毫秒）
         * @return
         */
        public Builder writeTimeout(long writeTimeout) {
            this.writeTimeout = writeTimeout;
            return this;
        }

        /**
         * 构造ConnRuler实体
         * @return
         */
        public ConnRuler build(){
            return new ConnRuler(this);
        }
    }
}
